package com.xbongbong.saas.model.team;

import com.xbongbong.saas.domain.dao.UserAndDepTeamDao;
import com.xbongbong.saas.domain.entity.CommonVisibleRangeTeamEntity;
import com.xbongbong.saas.domain.entity.UserAndDepTeamEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李翔
 * @date 2022/11/10
 * @description
 */
@Service("userAndDepTeamModel")
public class UserAndDepTeamModelImpl implements UserAndDepTeamModel{
    @Resource
    private UserAndDepTeamDao userAndTeamDao;

    @Override
    public List<UserAndDepTeamEntity> findBaseEntitys(Map<String, Object> param, String table) {
        return userAndTeamDao.findBaseEntitys(param, table);
    }

    @Override
    public List<CommonVisibleRangeTeamEntity> findEntitys(Map<String, Object> param, String table) {
        return userAndTeamDao.findEntitys(param, table);
    }

    @Override
    public CommonVisibleRangeTeamEntity getByKey(Long key, String corpid, String table) {
        Map<String, Object> param = new HashMap<>();
        param.put("corpid", corpid);
        param.put("id", key);
        param.put("del", 0);
        List<CommonVisibleRangeTeamEntity> entitys = userAndTeamDao.findEntitys(param, table);
        if (CollectionUtils.isNotEmpty(entitys) && entitys.size() < 2) {
            return entitys.get(0);
        }
        return new CommonVisibleRangeTeamEntity();
    }

    @Override
    public Integer deleteByKey(Long key, String corpid, String table) {
        return userAndTeamDao.deleteByKey(key, corpid, table);
    }
}
